#ifndef MYPLUGIN_H
#define MYPLUGIN_H

#include <QObject>
#include <QString>
#include <QtQml/qqml.h>  // 必须包含

class MyPlugin : public QObject {
    Q_OBJECT
    QML_ELEMENT  // 自动注册到 QML
    //QML_NAMED_ELEMENT(MyQmlType) //定义模块名字
    Q_PROPERTY(QString message READ message WRITE setMessage NOTIFY messageChanged)

public:
    explicit MyPlugin(QObject *parent = nullptr);

    QString message() const;
    void setMessage(const QString &message);

    Q_INVOKABLE void showMessage(const QString &text);

signals:
    void messageChanged();

private:
    QString m_message;
};


//关键：注册函数
static void registerTypes() {
    qmlRegisterType<MyPlugin>("com.mycompany.plugin", 1, 0, "MyPlugin");
}

// 导出插件
// Q_COREAPP_STARTUP_FUNCTION(registerTypes);


#endif // MYPLUGIN_H
